<?php
class XXmlViewer extends ContentFile
{
	const S_XSL_DIR = "../xsl";
	
	/**
	 * @param ServerResponse $oResponse
	 * @param String $sAbsolutePath
	 */
	public function readContent( $oResponse, $sAbsolutePath )
	{		
		require_once( 'io.php' );
	
	  // Find corresponding xsl file (using the filename convention)
	  $sFileExtension 	= FileManager::getLongFileExtension( $sAbsolutePath );
	  $sTmpArray       	= explode( ".", $sFileExtension );
	  if ( sizeof( $sTmpArray ) < 2 )
	  {
	  	$oResponse->error( "The file extension of ".$sAbsolutePath." doesn't follow the convention : DIR/DIR/NAME.TYPE.xml (e.g. content/test.char.xml)" );
	  	return;
	  }
	  
	  $sFileType       = $sTmpArray[ sizeof( $sTmpArray ) - 2 ];
	  $sXslFileName    = $this->S_XSL_DIR."/html.".$sFileType.".xsl";
	  if( !file_exists( $sXslFileName ) )
	  {
	  	$oResponse->error( "Cannot find the corresponding xsl file : ".$sXslFileName );
	  	return;
	  }
	  
	  // transform data
	  $sTransformedData = FileManager::xml2html( $oResponse, $sAbsolutePath, $sXslFileName );
	  
	  $oResponse->data( $sTransformedData );
	  
	  $oResponse->requestExecuted();
	}
} 
?>